package tichu_project252.Round;

import java.util.LinkedList;
import tichu_project252.CardClasses.Card;
import tichu_project252.Table;

public class singleCard extends TurnType {

    /**
     * Returns true if the combination given is Single card.
     *
     * <p> <b> Accessor(Selector): </b> isSingleCard(LinkedList <Card> l, Table
     * t) </p>
     *
     * <p><b> Precondition: </b> The player should select some cards.</p> </p>
     * <p> <b> Postcondition:</b> Returns true if the combination is a single
     * card, else it returns false. </p>
     *
     * @return if the combination is single card.
     */
    public static boolean isSingleCard(LinkedList<Card> l, Table t) {

        LinkedList<Card> temp = t.getLastDropped();  // The previous cards that are in the table


        if (l.size() == 1) {
            if (temp.size() == 0) {                                 // if there is no cards in the table, play this combination.
                return true;
            }

            if (l.size() != temp.size()) {                          // if the selected cards are more or less, from the previous cards thrown on table the combination is invaled
                return false;
            }

            if ("Drache".equals(l.get(0).getstringRepr())) {        //Dragon win every single card
                return true;
            }

            if ("Phoenix".equals(l.get(0).getstringRepr())) {           //if phoenix is thrown is bigger than the last single card except it was a dragon
                return !"Drache".equals(temp.get(0).getstringRepr());
            }


            return temp.get(0).getintRepr() < l.get(0).getintRepr(); // return true if the previous combination was smaller that the current one

        }
        return false;  // if the size is not in 1 we are not in this case.
    }
}
